package com.ffcs.web.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.ffcs.web.daos.implementations.AdvertDao;
import com.ffcs.web.model.dto.Pingjia;
import com.ffcs.web.model.dto.QuestionType;
import com.ffcs.web.model.entity.Advert;
import com.ffcs.web.utils.CommonConfig;

@Service
public class AdvertService {

	@Autowired
	private AdvertDao advertDao;
	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<Advert> getAdvertPic(String type) {
		List<Advert> list=advertDao.findByPropertyNameWithOrder("type", Short.parseShort(type), "updateTime",false);
		for (Advert ad: list) {
			ad.setUrl(CommonConfig.getProperty("PIC_URL_FRONT")+ad.getUrl());
		}
		return list;
	}

	public List<QuestionType> getQuestionType(String type) {
		String sql="select * from wechat_question_type where id="+type;
		return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<QuestionType>(QuestionType.class));
	}

	/**
	 * 获取首页轮播ID
	 * @param advertId
	 * @return
	 */
	public Advert getAdvert(String advertId) {
		return advertDao.get(Integer.parseInt(advertId));
	}

	public List<Advert> getAdvertPic2(String advertType) {
		String sql="select * from wechat_advert where type=0 and advertType="+advertType+" order by updateTime desc ";
		return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<Advert>(Advert.class));
	}
}
